package com.huawei.codearts.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huawei.codearts.mapper.WbIpMapper;
import com.huawei.codearts.model.WbIp;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class WbIpServiceImpl extends ServiceImpl<WbIpMapper, WbIp> implements WbIpService {

    @Autowired  // 自动装载的字段
    private WbIpMapper wbIpMapper;

    public Boolean getIp(String ip) {

        // 查询表中是否有此IP，并且状态是打开的状态
        // 白名单 方便测试先关闭
//        WbIp whiteIp = wbIpMapper.selectOne(new QueryWrapper<WbIp>().eq("ip", ip).eq("type", 1).eq("state", 1));
//        WbIp whiteIp = wbIpMapper.getIpOne(ip, 1, 1);
//        System.out.println("whiteIp..."+whiteIp);
//        if (whiteIp == null) {
//            return false;
//        }

        // 黑名单
        WbIp blackIp = wbIpMapper.getIpOne(ip, 2, 1);
        System.out.println("blackIp..."+blackIp);
        if (blackIp != null) {
            return false;
        }

        return true;
    }

}


